package com.yike.user.controller.feign;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yike.common.base.BaseController;
import com.yike.user.api.service.UserFeignService;
import com.yike.user.api.vo.UserVo;
import com.yike.user.convert.UserFeignConvert;
import com.yike.user.entity.User;
import com.yike.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Set;

/**
 * 权限表 控制器
 *
 * @author yike
 * @since 2023-08-24
 */
@RestController
@RequestMapping("/feign/user")
@ApiIgnore // 暂时不显示到文档
public class UserFeignController extends BaseController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public List<UserVo> list(@RequestParam("userIds") Set<Long> userIds) {
        Wrapper wrapper = Wrappers.lambdaQuery(User.class).in(User::getId,userIds);
        List<User> list = userService.list(wrapper);
        return UserFeignConvert.INSTANCE.convert(list);
    }

    @GetMapping("/getUserById")
    public UserVo getUserById(@RequestParam("userId") Long userId) {
        User user = userService.getById(userId);
        return UserFeignConvert.INSTANCE.convert(user);
    }
}

